import Navigate2enterpriseAnalysis from '@/mixins/navigate2enterpriseAnalysis'

export default {
  mixins: [Navigate2enterpriseAnalysis],
  mounted () {
    setTimeout(() => {
      this.bindClickEvent()
    }, 20)
  },
  beforeDestroy () {
    this.unbindClickEvent()
  },
  methods: {
    clickHandler (e) {
      const adcode = e.region ? e.region.adcode : ''
      // 1-企业地图 2-区域地图 3-行业地图
      const type = Number(this.type)
      if (adcode) {
        this.navigateToEnterpriseAnalysis({ id: adcode }, 'districtCode')
      }
      if (e.seriesType === 'effectScatter') {
        const data = e.data
        const row = {
          id: type === 1 ? data.id : type === 2 ? data.districtBelong : data.belongIndustry
        }
        const key = type === 1 ? 'enterpriseCode' : type === 2 ? 'districtCode' : 'industryCode'
        this.navigateToEnterpriseAnalysis(row, key)
      }
    },
    bindClickEvent () {
      const chart = this.chart
      if (chart) {
        chart.on('click', this.clickHandler)
      }
    },
    unbindClickEvent () {
      const chart = this.chart
      if (chart) {
        chart.off('click', this.clickHandler)
      }
    },
  }
}
